package a8;

public class RootApproximator {
	/**
	 * 
	 * @param a Number to take root of
	 * @param EPSILON Margin of error
	 */
	public RootApproximator(int a, double EPSILON) {
		this.EPSILON = EPSILON;
		this.a = a;
		guess = 1;
		moreGuess = true;
	}
	/**
	 * 
	 * @return Next root guess
	 */
	public double nextGuess() {
		guess = (guess + (a/guess))/2;
		if(Math.abs(Math.sqrt(a)-guess) <= EPSILON)
			moreGuess = false;
		return guess;
	}

	/**
	 * 
	 * @return If next root can be calculated
	 */
	public boolean hasMoreGuesses() {
		return moreGuess;
	}

	private double guess;
	private double EPSILON;
	private int a;
	private boolean moreGuess;

}


